package cn.hairui.fastms.core.annotation;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * <h2>请添加简述</h2>
 *   <ol>请添加详细描述</ol>
 * <h2>修改历史</h2>
 *   <ol>如有修改，请添加修改历史</ol>
 * </p>
 *
 * @author spdb/lihr3
 * @date 2020/12/26 13:09
 * @copyright spdb
 */
@SuppressWarnings("ALL")
public class ObjConvertUtils {

    /**
     * 获取类的所有属性，包括父类
     *
     * @param object
     * @return
     */
    public static Field[] getAllFields(Object object) {
        Class<?> clazz = object.getClass();
        List<Field> fieldList = new ArrayList<>();
        while (clazz != null) {
            fieldList.addAll(new ArrayList<>(Arrays.asList(clazz.getDeclaredFields())));
            clazz = clazz.getSuperclass();
        }
        Field[] fields = new Field[fieldList.size()];
        fieldList.toArray(fields);
        return fields;
    }

    public static boolean isEmpty(Object object) {
        if (object == null) {
            return (true);
        }
        if ("".equals(object)) {
            return (true);
        }
        if ("null".equals(object)) {
            return (true);
        }
        return (false);
    }
}